package top.leyi.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import top.leyi.entity.Commodity;
import top.leyi.entity.SQLUtil;

import java.util.List;

public interface CommMapper {

    /**
     * @descripe 分页查询
     * @param util
     * @return
     */
    @Select("SELECT c.* ,u.id  as userId,u.username FROM commodity c join user u where u.id = c.user_id ORDER BY c.id DESC " +
            "LIMIT #{limit} OFFSET  #{offset} ")
    List<Commodity> queryAllCommdity(SQLUtil util);

    /**
     * @descripe 分页查询
     * @param util
     * @return
     */
    @Select("SELECT c.* ,u.id  as userId,u.username FROM commodity c join user u " +
            "where u.id = c.user_id and c.name LIKE '%${key}%'" +
            "ORDER BY c.id DESC " +
            "LIMIT #{limit} OFFSET  #{offset} ")
    List<Commodity> fuzzyQueryAllCommdity(SQLUtil util);

    /**
     * @descripe 插入一个商品
     * @param util
     * @return
     */
    @Insert("INSERT INTO commodity(price, phone, name, descripe, pics, user_id) " +
            "VALUES(#{price},#{phone},#{name},#{descripe},#{pics},#{userId})")
    void addOneCommodity(Commodity commodity);

}
